<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!doctype html>
<html lang="zh">
<head>
    <title>HSE安全信息管理系统-登录</title>
    <%--兼容IE9一下版本--%>
    <script type="text/javascript" src="${ctx}/resources/js/common/css3-mediaqueries.js"></script>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <link href="${ctx}/resources/easyui/themes/insdep/easyui.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/resources/easyui/themes/insdep/default_theme.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/resources/easyui/themes/insdep/icon.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/resources/themes/style/layout.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/resources/themes/style/login.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/resources/themes/style/font-awesome.min.css" rel="stylesheet" type="text/css">
    <script type="text/javascript">
        var ROOT_PATH = '${ctx}';
    </script>
    <script type="text/javascript" src="${ctx}/resources/jquery/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="${ctx}/resources/layer/layer.js"></script>
    <!--js模板-->
    <script type="text/javascript" src="${ctx}/resources/template/template.js"></script>
    <%--日期操作--%>
    <script type="text/javascript" src="${ctx}/resources/moment/moment-with-locales.min.js"></script>
    <script type="text/javascript" src="${ctx}/resources/js/common/util.js"></script>
    <!--常量配置文件-->
    <%--<script type="text/javascript" src="${ctx}/config/constantProperties.js"></script>--%>

    <script type="text/javascript" src="${ctx}/resources/jquery/base64.js"></script>
</head>
<body>
   <div class="login-title">
       <h2>
           <img src="${ctx}/resources/themes/images/login_title_03.png">
       </h2>
   </div>
      <div class="entry">
            <div class="userLogin">
                  <div class="user-header">
                       <img src="${ctx}/resources/themes/images/user_03.png">
                      <h3>用户登录 <span>USER LOGIN</span></h3>
                  </div>
                <form class="login-form" id="login_form">
                    <div class="user-name">
                        <label>用户名：</label>
                        <input type="text" class="input-syle" name="userName" id="userName" title="">
                    </div>
                     <div class="user-password">
                         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label>密码：</label>
                         <input type="password" class="input-syle" name="password" id="password" title="">
                     </div>
                    <div class="remember">
                        <input type="checkbox"  name="checkbox" class="bear" title="" id="bearPwd">记住密码
                    </div>
                    <div class="push-button">
                         <button type="submit" class="button-one" id="login">登 录</button>
                         <button type="reset" class="button-two">重 置</button>
                    </div>
                </form>
            </div>
      </div>
   <script>

       if(window !=top){
           top.location.href=location.href;
       }

       $(function () {
           var storage = window.localStorage;
           var b = new Base64();
           var userName=storage["userName"] ;
           var password=storage["password"];
           var bearPwd=storage["bearPwd"];
           if(bearPwd){
               $('#bearPwd').attr("checked",true);
               $('#userName').val(userName);
               $('#password').val(b.decode(password));
           }

           $('#login_form').on('submit', function (e) {
               e.preventDefault();
               var $userName=$('#userName').val();
               var $password=$('#password').val();
               if($userName!='' && $password !=''){
                   $.ajax({
                       type: "POST",
                       url: ROOT_PATH+'/login.shtml',
                       data: {userName:$userName,password:$password},
                       dataType: "json",
                       success: function(data){
                           var icon=1;
                           if(data.success){
                               if($('#bearPwd').is(':checked')){
                                   storage["userName"] =$userName;
                                   storage["password"] =b.encode($password)  ;
                                   storage["bearPwd"] = true;
                               }
                               //验证成功跳转主页
                               window.location.href=ROOT_PATH+'/index.shtml';
                           }else{
                               //验证出错
                               icon=2;
                               $('#bearPwd').attr("checked",false);
                               $('#password').val("");
                               storage.removeItem("userName");
                               storage.removeItem("password");
                               storage.removeItem("bearPwd");
                           }
                           layer.msg(data.message,{time:1000,icon:icon});
                       }
                   });
               }else{
                   layer.alert("账号或密码不能为空",{time:1000,icon:2});
               }

           });

       });

   </script>
</body>
</html>
